package cn.fw.community.client.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import io.gitee.chearnee.fw.common.annotation.IBaseEnumJson;
import io.gitee.chearnee.fw.common.model.IBaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum ActionEventEnum implements IBaseEnum<String> {
    START_APP("startapp", "打开app"),
    CLICK("click", "点击"),
    EXIT_APP("exitapp", "退出app"),
    OPEN_BACKGROUND("openbackground", "打开后台"),
    CLOSE_BACKGROUND("closebackground", "关闭后台"),
    SHOW("show", "浏览事件(记录浏览时长)"),
    ENTER("enter", "进入页面"),
    ;
    @EnumValue
    @IBaseEnumJson
    private final String value;
    private final String desc;

    private static Map<String, ActionEventEnum> enumMap;

    public static ActionEventEnum valueOfValue(String actionString) {
        if (enumMap == null) {
            enumMap = Arrays.stream(values()).collect(Collectors.toMap(ActionEventEnum::getValue, Function.identity()));
        }
        return enumMap.get(actionString);
    }

}
